package org.lisa.crm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.lisa.crm.common.util.Result;
import org.lisa.crm.common.util.StringUtil;
import org.lisa.crm.dao.CusDevPlanDao;
import org.lisa.crm.model.CusDevPlan;
import org.lisa.crm.service.CusDevPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by admin on 2018/1/29.
 */
@Service
public class CusDevPlanServiceImpl implements CusDevPlanService {

    @Autowired
    private CusDevPlanDao cusDevPlanDao;

    @Override
    public Result insertCusDevPlan(CusDevPlan cusDevPlan) {

        cusDevPlan.setCreateDate(new Date());

        cusDevPlan.setIsValid(1);

        int res=cusDevPlanDao.saveSte(cusDevPlan);

        if(res == 1){
            return Result.success("保存成功");
        }

        return Result.fail("保存失败");

    }

    @Override
    public Map<String, Object> queryCusDevPlansByParams(CusDevPlan cusDevPlan) {

        Map<String,Object> map = new HashMap<>();
        map.put("isValid",1);
        map.put("saleChanceId",cusDevPlan.getSaleChanceId());
        List<CusDevPlan> list=cusDevPlanDao.find(map);

        //分页
        PageHelper.startPage(cusDevPlan.getPage(),cusDevPlan.getRows());

        //创建一个包装了分页信息的分页对象,将list作为入参
        PageInfo<CusDevPlan> info = new PageInfo<>(list);

        Map<String,Object> map1=new HashMap<>();
        map1.put("total",info.getTotal());
        map1.put("rows",info.getList());

        return map1;
    }

    @Override
    public Result deleteCusDevPlan(CusDevPlan cusDevPlan) {
        int res=cusDevPlanDao.delete(cusDevPlan.getId());

        if(res == 1){
            return Result.success("删除成功");
        }

        return Result.fail("删除失败");
    }
}
